//
// Created by void on 24-3-17.
//
#ifndef CDATETIME_H
#define CDATETIME_H

#include <ctime>
#include <string>
namespace iotplat {
    class CDateTime {
    public:
        CDateTime(std::time_t time = std::time(nullptr));

        static CDateTime FromString(const std::string &timeStr, const std::string &format = "%Y-%m-%d %H:%M:%S");

        std::string ToString(const std::string &format = "%Y-%m-%d %H:%M:%S") const;

        CDateTime& operator=(const CDateTime& other) {
            if (this != &other) { // 避免自赋值
                time_ = other.time_; // 直接复制time_成员
            }
            return *this; // 返回*this以支持链式赋值
        }

        int GetYear() const;

        int GetMonth() const;

        int GetDay() const;

        void SetYear(int year);

        void SetMonth(int month);

        void SetDay(int day);

        bool IsSameDate(const CDateTime &other) const;

        CDateTime AddDays(int days) const;

        std::time_t GetTime() const;

        void SetTime(std::time_t time);

        static CDateTime Now();

    private:
        std::time_t time_;
    };
}
#endif // CDATETIME_H
